import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:guochaoapp/common/widges/appbar.dart';
import 'package:guochaoapp/controller/mine/invoice_controller.dart';
import 'package:guochaoapp/r.dart';

class GCInvoicePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    GCInvoiceController c = Get.put(GCInvoiceController());
    return Scaffold(
      appBar: GCAppBar(
        titleText: "发票信息管理",
        actions: [
          Obx(() {
            if (c.invoiceData.value != null) {
              return Row(
                children: [
                  GestureDetector(
                    onTap: c.submitTap,
                    child: Text("清除", style: TextStyle(color: Colors.white)),
                  ),
                  SizedBox(width: 23)
                ],
              );
            } else {
              return Row(
                children: [
                  GestureDetector(
                      onTap: c.submitTap,
                      child: Image.asset(R.assetsIconAddressadd,
                          width: 20, height: 20)),
                  SizedBox(width: 23)
                ],
              );
            }
          }),
        ],
      ),
      body: Obx(() {
        if (c.invoiceData.value != null) {
          return _initSubviews();
        } else {
          return _noDataView();
        }
      }),
    );
  }

  _initSubviews() {
    GCInvoiceController c = Get.put(GCInvoiceController());

    var values = [
      c.invoiceData.value.companyName,
      c.invoiceData.value.taxpayerIdNum,
      c.invoiceData.value.registerAddr,
      c.invoiceData.value.registerPhone,
      c.invoiceData.value.branchName,
      c.invoiceData.value.cardNo,
      c.invoiceData.value.receiverName,
      c.invoiceData.value.receiverPhone,
      c.invoiceData.value.receiverAddr,
    ];
    return ListView(
      children: [
        ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemCount: c.titles.length,
            itemBuilder: (contenxt, index) {
              return Container(
                height: 45,
                color: Colors.white,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Row(
                      children: [
                        SizedBox(width: 20),
                        Text(
                          c.titles[index],
                          style:
                              TextStyle(color: Color(0xFF666666), fontSize: 16),
                        ),
                        Expanded(child: SizedBox()),
                        Text(
                          values[index],
                          style: TextStyle(color: Colors.black, fontSize: 16),
                        ),
                        SizedBox(width: 10),
                      ],
                    ),
                    Container(
                      height: index == 5 ? 20 : 0,
                      child: Column(
                        children: [
                          Container(height: 10, color: Colors.white),
                          Container(height: 10, color: Color(0xFFF4F8FE)),
                        ],
                      ),
                    ),
                  ],
                ),
              );
            }),
        SizedBox(height: 30),
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: 248,
              height: 37,
              child: RaisedButton(
                  color: Theme.of(Get.context).primaryColor,
                  onPressed: c.editTap,
                  child: Text(
                    "修改",
                    style: TextStyle(color: Colors.white),
                  )),
            ),
          ],
        )
      ],
    );
  }

  _noDataView() {
    return Container(
        width: ScreenUtil().screenWidth,
        height: ScreenUtil().screenHeight,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(
              R.assetsIconNoInvoice,
              width: 156,
              height: 158,
            )
          ],
        ));
  }
}
